fix(printer): use @page size:auto so thermal receipts print full-size#625
fix(printer): use @page size:auto so thermal receipts print full-size#625kilbot wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
kilbot has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
📝 WalkthroughWalkthroughThe pageSize computation for thermal (non-a4) receipt widths in buildPrintableReceiptHtml was changed to append "auto" to the width value, allowing flowing height instead of a fixed square page size. Corresponding tests were updated to reflect this new ChangesThermal page sizing fix
Estimated code review effort: 1 (Trivial) | ~5 minutes PoemA rabbit hopped to print a bill, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
The real problem: CSS Reworking toward a spec-valid fix (either |
📊 Test Coverage Report
Coverage Legend
|
🚀 Deployment Summary
🤖 Updated by GitHub Actions |
The system/HTML print path emitted `@page { size: 80mm }` (or 58mm) for
thermal receipt templates. A single CSS length in the `size` descriptor sets
*both* page dimensions, so the page box became an 80mm×80mm square. Electron
prints via the interactive `window.print()` dialog, which honours `@page`, then
shrinks that square onto the printer's roll paper (e.g. 80×297mm), rendering the
receipt tiny and unreadable.
The previous value `${paperWidth} auto` is not a fix either: the `@page size`
grammar is `<length>{1,2} | auto | <page-size>`, so `80mm auto` is invalid and
browsers ignore it, falling back to Letter/A4 (this was the P1 Codex finding on
#429 that a499ded changed to the square `80mm`). CSS cannot express a
fixed-width, content-height page.
Emit `size: auto` for thermal so the browser uses the thermal printer's own
roll paper and shrink-fits the content to the roll width. Update the print-html
tests to assert `size: auto` and guard against both broken forms; add 58mm
coverage. Ships broken in v1.9.0–v1.9.6.
Final on-device confirmation on a real thermal printer still recommended.
fbb7aee to
e17e833
Compare
Problem
After updating to a 1.9.x build, printing to a thermal receipt printer via the system print dialog produces a tiny, unreadable receipt floated at the top of the page instead of one that fills the 80mm roll.
Root cause
buildPrintableReceiptHtmlemitted@page { size: 80mm }(or58mm) for thermal templates. A single length in the CSSsizedescriptor sets both page dimensions → an 80mm × 80mm square page (verified in headless Chromium: the generated HTML renders to an 80.1×80.1mm PDF). Electron prints through the interactivewindow.print()dialog (apps/electron/src/main/print-external-url.ts, via adata:URL fromsystem-print-adapter.electron.ts), which honours@page; the browser then shrinks that square onto the printer's real roll paper (80 (72) × 297mm) → the tiny result.Why the previous value wasn't the fix either
Before
a499ded9c, this emitted${paperWidth} auto(80mm auto). But the@page sizegrammar is<length>{1,2} | auto | <page-size>— there is no "length + auto" form.80mm autois invalid; browsers ignore it and fall back to Letter/A4 (confirmed:215.9×279.4mm). That was the P1 Codex finding on #429, whicha499ded9c"fixed" by switching to the valid-but-square80mm. So:80mm auto(pre-a499ded9c)80mm(shipped v1.9.0–v1.9.6)auto(this PR)CSS
@page sizecannot express a fixed-width, content-height page, so we defer to the printer's own paper.Fix
Emit
@page { size: auto; margin: 0; }for thermal templates (A4 unchanged). The browser uses the thermal printer's selected roll paper (e.g. 80×297mm) and shrink-fits the receipt content to the roll width.Tradeoff: this relies on the user's printer being set to its thermal roll paper (which it is for a thermal printer). It does not force an 80mm width if a thermal template is sent to an A4 printer — an uncommon case. A width-forcing alternative would require measuring the rendered height and emitting a valid two-length
size: 80mm <height>mm, which needs changes in the Electron main print flow (submodule) and was deliberately deferred.Testing
packages/printervitest: 409 passed, incl. updated assertions that thermal emitssize: autoand guards against both broken forms (80mmsquare and invalid80mm auto); added 58mm coverage.pnpm run lint— 0 errors;pnpm typecheck --force— passes.autoLetter fallback (215.9×279.4mm) in headless Chromium.Headless/PDF backends don't model a thermal printer's roll paper, so the
size: autorender must be confirmed on a real thermal printer (e.g. the PRP-250C in the original report) before release. This is the one step I can't do here.Merchant workaround (no update needed)